package com.yuyou.fn.settlement.service.impl;

import com.github.wens.framework.service.impl.SuperServiceImpl;
import com.github.wens.mybatisplus.examples.Example;
import com.yuyou.fn.settlement.entity.TradeProp;
import com.yuyou.fn.settlement.mapper.TradePropMapper;
import com.yuyou.fn.settlement.service.ITradePropService;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 *
 * TradeProp 表数据服务层接口实现类
 *
 */
@Service
public class TradePropServiceImpl extends SuperServiceImpl<TradePropMapper, TradeProp,Long> implements ITradePropService {

    @Override
    public Map<String,String> findByTradeId(Long tradeId) {
        Example<TradeProp> example=TradeProp.createExample();
        Example.Criteria criteria=example.createCriteria();
        criteria.andEqualTo("tradeId",tradeId);
        List<TradeProp> list = findListByExample(example);
        Map<String,String> map = new HashMap<>();
        for(TradeProp tradeProp : list ){
            map.put(tradeProp.getName(),tradeProp.getValue() );
        }
        return map ;
    }

    @Override
    public List<TradeProp> findByTradeIds(List<Long> tradeIds) {
        if (tradeIds==null || tradeIds.size()<=0) {
            return new ArrayList<TradeProp>(0);
        }
        Example<TradeProp> example=TradeProp.createExample();
        Example.Criteria criteria=example.createCriteria();
        criteria.andIn("tradeId",tradeIds);
        return findListByExample(example);
    }

    @Override
    public List<TradeProp> findValueByTradeIdsName(List<Long> tradeIds, String name) {
        Example<TradeProp> example=TradeProp.createExample();
        example.selectProperties("tradeId","name","value");
        Example.Criteria criteria=example.createCriteria();
        criteria.andIn("tradeId",tradeIds).andEqualTo("name",name);
        return findListByExample(example);
    }

    @Override
    public List<TradeProp> findValueByTradeIdsNames(List<Long> tradeIds, String... names) {
        Example<TradeProp> example=TradeProp.createExample();
        example.selectProperties("tradeId","name","value");
        Example.Criteria criteria=example.createCriteria();
        criteria.andIn("tradeId",tradeIds).andIn("name", Arrays.asList(names));
        return findListByExample(example);
    }
}